<?php
// No directAcces
defined( '_AppMiage' ) or die( 'Restricted access' );
if(isEntreprise ()){
    //include header
    include_once (DS.'include/header.php');
    //include menu
    include_once (DS.'include/menu.php');

    $showOK = false;
    $showError = false;

    //récupération des infos sur l'entreprise affilié au contactEntreprise
    $entreprise = new Entreprise($global_member->getIdEntreprise());

    if(isset($_POST['submit']))
    {
            // variable qui va nous servir pour savoir s'il y a a eu une erreur ;)
            $form = true;
            $errMSG = array();

            /* --------------------- INFORMATIONS -----------------------*/
            if(isset($_POST['lastname']) && !empty($_POST['lastname']))
            {
                    $tmp = $entreprise->setNomEntreprise($_POST['lastname']);
                    if($tmp['boolOk'] === false)
                    {
                            $errMSG['nom'] = $tmp['errmsg'];
                            $form = false;
                    }
            }

            if(isset($_POST['description']) && !empty($_POST['description']))
            {
                    $tmp = $entreprise->setDescriptionEntreprise($_POST['description']);
                    if($tmp['boolOk'] === false)
                    {
                            $errMSG['description'] = $tmp['errmsg'];
                            $form = false;
                    }
            }
            /* ------------------ FIN INFORMATIONS ---------------------*/

            /* ----------------------- CONTACT -------------------------*/
            if(isset($_POST['email']) && !empty($_POST['email']))
            {
                    $tmp = $entreprise->setMailEntreprise($_POST['email']);
                    if($tmp['boolOk'] === false)
                    {
                            $errMSG['mail'] = $tmp['errmsg'];
                            $form = false;
                    }
            }

            if(isset($_POST['tel']) && !empty($_POST['tel']))
            {
                    $tmp = $entreprise->setTelephoneEntreprise($_POST['tel']);
                    if($tmp['boolOk'] === false)
                    {
                            $errMSG['tel'] = $tmp['errmsg'];
                            $form = false;
                    }
            }

            if(isset($_POST['site']) && !empty($_POST['site']))
            {
                    $tmp = $entreprise->setSiteEntreprise($_POST['site']);
                    if($tmp['boolOk'] === false)
                    {
                            $errMSG['site'] = $tmp['errmsg'];
                            $form = false;
                    }
            }
            /* -------------------- FIN CONTACT -----------------------*/

            /* ----------------------- ADRESSE ------------------------*/
            if(isset($_POST['adresse']) && !empty($_POST['adresse']))
            {
                    $tmp = $entreprise->setAdresse1Entreprise($_POST['adresse']);
                    if($tmp['boolOk'] === false)
                    {
                            $errMSG['add1'] = $tmp['errmsg'];
                            $form = false;
                    }
            }
            if(isset($_POST['adresse2']) && !empty($_POST['adresse2']))
            {
                    $tmp = $entreprise->setAdresse2Entreprise($_POST['adresse2']);
                    if($tmp['boolOk'] === false)
                    {
                            $errMSG['add2'] = $tmp['errmsg'];
                            $form = false;
                    }
            }
            if(isset($_POST['city']) && !empty($_POST['city']))
            {
                    $tmp = $entreprise->setVilleEntreprise($_POST['city']);
                    if($tmp['boolOk'] === false)
                    {
                            $errMSG['ville'] = $tmp['errmsg'];
                            $form = false;
                    }
            }
            if(isset($_POST['cp']) && !empty($_POST['cp']))
            {
                    $tmp = $entreprise->setCPEntreprise($_POST['cp']);
                    if($tmp['boolOk'] === false)
                    {
                            $errMSG['cp'] = $tmp['errmsg'];
                            $form = false;
                    }
            }
            /* -------------------- FIN ADRESSE -----------------------*/
            if($form === true)
        {
            $entreprise->updateEntreprise();
            if($entreprise->requeteOk === true)
            {
                $showOK = true;
            }
            else
            {
                $showError = true;
            }
        }
    }

    ?>
    <div id="content">
        <div class="post">
             <div class="entry">
                <h3 class="title">Modifier le Profil Entreprise</h3>
                <?php if($showError): ?>
                    <div class="error">Une erreur est survenue. Veuillez re-essayer ult&egrave;rieurement.</div>
                <?php endif; ?>
                <?php if($showOK): ?>
                    <div class="success">La modification du profil a &eacute;t&eacute; correctement effectu&eacute;e.</div>
                <?php endif; ?>
            </div>
            <div class="entry">
            <form id="form" method="post">

            <fieldset id="personal">
                <legend>Informations</legend>

                <label for="lastname">Nom : </label> <br />
                <input class="title" name="lastname" id="lastname" type="text" tabindex="1" value="<?php echo stripslashes($entreprise->getNomEntreprise()); ?>" />
                <?php if(isset($errMSG['nom'])){ echo $errMSG['nom']; } ?>

                <br />
                <label for="description">Description : </label> <br />
                <textarea class="title" name="description" id="description" type="text" tabindex="2"><?php echo $entreprise->getDescriptionEntreprise(); ?></textarea>
                <?php if(isset($errMSG['description'])){ echo $errMSG['description']; } ?>

                <br />
            </fieldset>

            <fieldset id="personal">
                <legend>Contact</legend>

                <label for="tel">Telephone : </label><br />
                <input class="title" name="tel" id="email" type="text"tabindex="3" value="<?php echo $entreprise->getTelephoneEntreprise(); ?>" />
                <?php if(isset($errMSG['tel'])){ echo $errMSG['tel']; } ?>

                <br />
                <label for="email">Email : </label><br />
                <input class="title" name="email" id="email" type="text"tabindex="4" value="<?php echo $entreprise->getMailEntreprise(); ?>" />
                <?php if(isset($errMSG['email'])){ echo $errMSG['email']; } ?>

                <br />
                <label for="site">Site : </label><br />
                <input class="title" name="site" id="site" type="text"tabindex="5" value="<?php echo $entreprise->getSiteEntreprise(); ?>" />
                <?php if(isset($errMSG['site'])){ echo $errMSG['site']; } ?>

            </fieldset>

            <fieldset id="address">
                <legend>Adresse</legend>

                <label for="adresse">Adresse : </label> <br />
                <input class="title" name="adresse" id="adresse" type="text" tabindex="6" value="<?php echo $entreprise->getAdresse1Entreprise(); ?>" />
                <?php if(isset($errMSG['adresse'])){ echo $errMSG['adresse']; } ?>

                <br />
                <label for="adresse2">Adresse + : </label> <br />
                <input class="title" name="adresse2" id="adresse2" type="text" tabindex="7" value="<?php echo $entreprise->getAdresse2Entreprise(); ?>" />
                <?php if(isset($errMSG['adresse2'])){ echo $errMSG['adresse2']; } ?>

                <br />
                <label for="city">Ville : </label><br />
                <input class="title" name="city" id="city" type="text" tabindex="8" value="<?php echo $entreprise->getVilleEntreprise(); ?>" />
                <?php if(isset($errMSG['city'])){ echo $errMSG['city']; } ?>

                <br />
                <label for="cp">Code Postal : </label> <br />
                <input class="title" name="cp" id="cp" type="text" tabindex="9" value="<?php echo $entreprise->getCPEntreprise(); ?>" />
                <?php if(isset($errMSG['cp'])){ echo $errMSG['cp']; } ?>
                <br />
            </fieldset>
            <div align="center">
                <input class="button green" type="submit" name="submit" value="Modifier" tabindex="10"  />
                <input class="button green" type="reset"tabindex="11"  />
            </div>
            </form>
            </div>
            </div>

    </div>
    <?php
    include_once (DS.'include/sidebar.php');

    include_once (DS.'include/footer.php');
}
else
{
    redirectTo();
}
?>
